package com.jservice.web.sysAndriodType;

import com.jfinal.aop.Before;
import com.jfinal.plugin.activerecord.Record;
import com.jservice.framework.annotation.RouteBind;
import com.jservice.framework.dto.Message;
import com.jservice.framework.dto.Pager;
import com.jservice.model.SmkAndriodType;
import com.jservice.model.SysOffice;
import com.jservice.model.SysUser;
import com.jservice.web.base.JBaseController;
import com.jservice.web.sysOffice.OfficeValidator;
import com.jservice.web.sysOffice.SysOfficeService;
import com.jservice.web.sysRole.SysRoleService;
import com.jservice.web.sysUser.SysUserService;

import java.util.List;

/**
 * @Author: huoo
 * @version: 1.0.0
 * @Description: 新增andriod机型维护
 * @Date: create in 11:00 2017/8/21
 * @Modified By:
 */
@RouteBind(path = "/admin/androidType")
public class AndroidTypeController extends JBaseController {


    @SuppressWarnings("rawtypes")
    public void list(){
        Pager pager = AndroidTypeService.me().findPage(getPageable());
        setAttr("pager",pager);
        render("list");
    }

    public void add() {
        render("add");
    }


    public void save(){
        SmkAndriodType smkAndriodType = getModel(SmkAndriodType.class);
        if(AndroidTypeService.me().androidTypeExists(smkAndriodType.getAndriodType())){
            render(ERROR_VIEW);
        }


        if(AndroidTypeService.me().save(smkAndriodType)){
            setFlashMessage(Message.success("机型添加成功"));
        }else{
            setFlashMessage(Message.error("机型添加失败"));
        }
        redirect("/admin/androidType/list");
    }

    public void edit() {
        String id = getPara("id");
        Record record = AndroidTypeService.me().findById(id);
        setAttr("smkAndriodType", record);
        render("edit");
    }

    public void update() {
        SmkAndriodType  smkAndriodType = getModel(SmkAndriodType.class);

        if(AndroidTypeService.me().update(smkAndriodType)){
            setFlashMessage(Message.success("机型更新成功"));
        }else{
            setFlashMessage(Message.error("机型更新失败"));
        }
        redirect("/admin/androidType/list");
    }



}
